<?php
	$TEMP->set_file(array('handle' => DIR_IFRAME_VIEW . 'transferCredits.html'));
	
	$CID 	= _GET('id');
	$SID 	= _GET('sid');
	
	$semesterLinker = $DSC->getSemesterLinker($CID);
	
	if ( (!empty($semesterLinker)) && (!empty($SID)) ) {
		$TEMP->set_block('handle',  'semester', 'semesterRow');
		$activeSubj  	= '';
		foreach($semesterLinker as $semesterLinkerField => $semesterLinkerValue) {
			
			$semDesc 	 = $semesterLinkerValue['sem_desc'];
			$semLinkerID = $semesterLinkerValue['sem_linker_idPK'];
			
			$semNote	 = (!empty($semesterLinkerValue['note'])) ? '*NOTE: ' . $semesterLinkerValue['note'] : '';
			
			$subjectListing = '';
			
			$subjectListingSemLinker = $DSC->getSubjectListingSemLinker($semLinkerID, $activeYear);
			
			if( !empty($subjectListingSemLinker) ) {
				$totalHRSTotal 	= 0;
				$totalUnits 	= 0;
				foreach($subjectListingSemLinker as $subjectListingSemLinkerValue) {
				
					$subjID 		= $subjectListingSemLinkerValue['subj_idPK'];
					$total_units 	= $subjectListingSemLinkerValue['total_units'];
					$totalHRS 		= $subjectListingSemLinkerValue['total_hrs'];
					$subjDesc 		= $subjectListingSemLinkerValue['subj_desc'];
					$co_req			= $subjectListingSemLinkerValue['co_req'];
					$pre_req		= $subjectListingSemLinkerValue['pre_req'];
					
					$total_units_parenthesis = ($total_units < 0) ? '(' . abs($total_units) . ')' : $total_units;
					
					$coChar  = (!empty($co_req)) ? $DSC->getReqSubjectID($co_req) : 'None';
					
					$preChar = (!empty($pre_req)) ? $DSC->getReqSubjectID($pre_req) : 'None';
					
					$lastInsert = ($subjectListingSemLinkerValue['subj_idPK'] == $LASTID) ? 'active-light' : '';
							
					$studentSubjectGrades = $STUD->getStudentSubjectGrades($SID, $subjID, $CID, $semLinkerID);
					$studSubjLInkerID 	  = $studentSubjectGrades['stud_subj_linker_idPK'];
					$studSubjGrade 	  	  = $studentSubjectGrades['grade'];
					$studSubjEquivalence  = $studentSubjectGrades['equivalence'];
				
					$activeSubj .= $studentSubjectGrades['subj_idFK'] . '-';
					
					$keyPressInput 	= ' onkeypress="return numberDate(event, false);" onfocus="viewSaveButton(\'' . $subjID . '\')"';
					
					$subjectListing .= '<tr align="center" class="hover-light ' . $lastInsert . '">
											<td class="transfery-td-bot" align="left">' . $subjDesc . '</td>
											<td class="transfery-td-bot">' . $subjectListingSemLinkerValue['subj_code'] . '</td>
											<td class="transfery-td-bot" align="left">
												<input type="hidden" id="id_transfer'. $subjID .'" value="' . $studSubjLInkerID . '"/>
												&nbsp;&nbsp;<input type="text" class="input-transfer-text ' . $blockInput . '" maxlength="5" value="' . $studSubjGrade . '" id="input_transfer'. $subjID .'" ' . $readOnlyInput . $keyPressInput . '/>
												<img src="' . DIR_IMAGES . 'icon/save.png" border="0" id="save_transfer'. $subjID .'" class="cursor-pointer display-none margin-transfery-top" onclick="saveGradeInput(\'' . $SID . '\', \'' . $subjID . '\', \'' . $CID . '\', \'' . $semLinkerID . '\',  \'' . $activeYear . '\')"/>
											</td>
											<td class="transfery-td-bot" align="center">
												<div class="transfery-convertion" id="transfery_grades'. $subjID .'">';
					$subjectListing .= 				(!empty($studSubjEquivalence)) ? $studSubjEquivalence : '<img src="' . DIR_IMAGES . 'icon/parallel_line.png" border="0"/>';
					$subjectListing .= '		</div>
											</td>
										</tr>';
					if ($total_units > 0) {
						$totalUnits = $totalUnits + $total_units;
					}
					$totalHRSTotal = $totalHRSTotal + $totalHRS;
				}
			}
			$TEMP->set_var(array('sem_desc' 			=> '<div class="subj-year-semester-value">' . $semDesc . '</div>',
								 'sem_linker_id' 		=> $semLinkerID,
								 'sem_note'				=> $semNote,
								 'subject_listing' 		=> $subjectListing));
			$TEMP->parse('semesterRow', 'semester', true);
		}
	}
	else {
		$TEMP->set_var(array('sem_desc' 			=> '',
							 'add_subject_button' 	=> '',
							 'sem_linker_id' 		=> '',
							 'subject_listing'		=> ''));
	}
	
	##################### CHECKLIST HEADER #####################
	
		$getCourse 	  = $DSC->getCourse($CID);
		$courseHeader = $DSC->getCourseHeader($getCourse['course_idPK']);
		$course_label	= $getCourse['course_desc'] . ' (' . $getCourse['course_code'] . ')';
	
	##################### CHECKLIST HEADER #####################
	
	$TEMP->set_var(array('search' 			=> $search,
						 'dept_course'		=> $courseHeader['dept_desc'],
						 'course_desc'		=> $course_label,
						 'course_id'		=> $CID,
						 'based'			=> $courseHeader['head_based'],
						 'year'				=> $courseHeader['head_year'],
						 'active_subj'		=> rtrim($activeSubj,'-'),
						));
?>